$(function () {
    let markid = getUrlString('markid');
    function userinfo() {
        getData('get', '/niu/apiv3/member_userinfo.php', {'markid':markid}, function (data) {
            console.log(data);
            $('#money11').html(data.data.money1);
            $('#money22').html(data.data.money2)
        })
    }
    userinfo();
    function exchange(type) {
        let shortid = $('#shortid').val();
        if (shortid === ''){
            laymsg('兑换码不能为空');
            return
        }
        let data = {
            'type':type,
            'shortid':shortid,
            'markid':markid
        };
        getData('get', '/niu/apiv4/niu_exchange_money3.php', data, function (data) {
            console.log(data);
            if (type === 'exchange') {
                if (data.resultcode === '200'){
                    $('.dtMoney').show();
                    if (data.info.money1 !== '0'){
                        $('#money1').html('：银币：'+data.info.money1);
                    }
                    if (data.info.money2 !== '0'){
                        $('#money1').html('：金币：'+data.info.money2);
                    }

                    if (data.info.money3 !== '0'){
                        $('#money1').html('：HP：'+data.info.money3);
                    }

                    if (data.info.money4 !== '0'){
                        $('#money1').html('：金币红包：'+data.info.money4);
                    }
                    let starttime = data.info.starttime.substring(0,4)+'-'+data.info.starttime.substring(4,6)+'-'+data.info.starttime.substring(6,8);
                    let endtime = data.info.endtime.substring(0,4)+'-'+data.info.endtime.substring(4,6)+'-'+data.info.endtime.substring(6,8);
                    $('#time').html('有效期：'+starttime+'--'+endtime );
                    if (data.info.isused === '0'){
                        $("#isShow").html('可使用')
                    } else {
                        $("#isShow").html('不可使用')
                    }
                    $('.dhBtn').hide();
                    $('.qddhBtn,.dhInfo').show();
                } else {
                    laymsg(data.msg)
                }
            }

            if (type === 'doexchange'){
                if (data.resultcode === '200'){
                    laymsg(data.msg);
                    $('.dtMoney,.qddhBtn,.dhInfo,.qddhBtn').hide();
                    $('#shortid').val('');
                    $('.dhBtn').show()
                }else {
                    $('.dtMoney,.qddhBtn,.dhInfo,.qddhBtn').hide();
                    $('#shortid').val('');
                    $('.dhBtn').show()
                    laymsg(data.msg)
                }
            }



        });
    }

    $('#dhBtn').click(function () {
        exchange('exchange')
    });

    $('.qddhBtn').click(function () {
        exchange('doexchange')
    });
});
